<template>
    <div>
      <home-header></home-header>
      <home-swiper :swiperList='swiperList'></home-swiper>
      <home-icons :iconList='iconList'></home-icons>
      <home-recommend :recommendList='recommendList'></home-recommend>
      <home-weekend :weekendList='weekendList'></home-weekend>
    </div>
</template>

<script>
import homeHeader from './compontents/Header.vue'
import HomeSwiper from './compontents/Swipers.vue'
import HomeIcons from './compontents/Icons.vue'
import HomeRecommend from './compontents/Recommend.vue'
import HomeWeekend from './compontents/Weekend.vue'
import axios from 'axios'
import { mapState } from 'vuex'
export default{
  name: 'Home',
  components: {
    homeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data ()  {
     return {
       lastCity: ' ',
       swiperList: [],
       iconList: [],
       recommendList: [],
       weekendList: []
     }
  },
  computed:{
    ...mapState(['city'])
  },
  methods:{
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city)
      .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
       res = res.data
      if(res.ret && res.data ){
          const data = res.data
          // this.city = data.city
          this.swiperList = data.swiperList
          this.iconList = data.iconList
          this.recommendList = data.recommendList
          this.weekendList =data.weekendList
      }
    }
  },
  mounted () {
    this.lastCity = this.city
      this.getHomeInfo()
  },
  activated() {
  if(this.lastCity !== this.city){
     this.lastCity = this.city
    this.getHomeInfo()
  }
  }
}
</script>
